package com.atguigu.jreechar;

import java.awt.Font;
import java.io.File;
import java.io.IOException;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.Plot;
import org.jfree.chart.urls.StandardCategoryURLGenerator;
import org.jfree.data.general.DefaultPieDataset;

public class JfreecharTest01 {

	public static void main(String[] args) throws IOException {
		// 获取DefaultPieDataSet
		DefaultPieDataset dataset = new DefaultPieDataset();
		// key（名称） value（数量）
		dataset.setValue("小米", 20);
		dataset.setValue("苹果", 5);
		dataset.setValue("360", 30);
		dataset.setValue("华为", 45);
		JFreeChart chart = ChartFactory.createPieChart("手机市场的占有率！", dataset);
		File file= new File("photo.jpg");
		ChartUtilities.saveChartAsPNG(file, chart, 800, 600);
		//设置字体
		chart.getTitle().setFont(new Font("宋体",Font.BOLD,50));//标题
		chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 30));//图列
		//绘图区
		Plot plot = chart.getPlot();
		PiePlot piePlot=(PiePlot) plot;
		
		piePlot.setLabelFont(new Font("宋体",Font.BOLD,15));
		piePlot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0},{1}/{3},{2}"));
	}

}
